package com.lecyon.farm.controller;

/**
 * @author Yao Zheng
 * @Date 2020/4/7 9:42
 */

import com.lecyon.farm.base.BaseRequestVo;
import com.lecyon.farm.base.RestResponse;
import com.lecyon.farm.service.IFmPictureService;
import com.lecyon.farm.service.impl.FmPictureService;
import com.lecyon.farm.util.ResultUtil;
import com.lecyon.farm.vo.query.QueryFmPictureVo;
import com.lecyon.farm.vo.sync.SyncPhotoInfo;
import com.lecyon.farm.vo.view.FmPictureInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;

/**
 * 农机作业图片 Controller
 *
 * @author YaoZheng
 * @since 2020-04-02
 */
@RestController
@RequestMapping("/fm-picture")
@Api(tags = "农机作业图片")
@ResponseBody
@CrossOrigin
public class FmPictureController {

    private FmPictureService fmPictureService;

    private IFmPictureService iFmPictureService;

    @Autowired
    public FmPictureController(FmPictureService fmPictureService, IFmPictureService iFmPictureService) {
        this.fmPictureService = fmPictureService;
        this.iFmPictureService = iFmPictureService;
    }

    @ApiOperation(value = "查询图片数量(FP0101)", notes = "查询图片数量(分页)，author:YaoZheng")
    @PostMapping(value = "/countAll")
    public RestResponse<Integer> countAll(@RequestBody @Valid BaseRequestVo<QueryFmPictureVo> vo) {
        QueryFmPictureVo queryCondition = vo.getEntity(QueryFmPictureVo.class);
        return fmPictureService.countAll(queryCondition);
    }

    @ApiOperation(value = "查询图片列表(FP0101)", notes = "查询图片列表(分页)，author:YaoZheng")
    @PostMapping(value = "/findByCarIdAndWorkDate")
    public RestResponse<List<FmPictureInfo>> findByCarIdAndWorkDate(@RequestBody @Valid BaseRequestVo<QueryFmPictureVo> vo) {
        QueryFmPictureVo queryCondition = vo.getEntity(QueryFmPictureVo.class);
        return fmPictureService.findByCarIdAndWorkDate(queryCondition);
    }

    @ApiOperation(value = "查询图片列表(FP0101)", notes = "查询图片列表(分页)，author:YaoZheng")
    @PostMapping(value = "/getPictureInfoList")
    public RestResponse<List<SyncPhotoInfo>> getPictureInfoList(@RequestBody @Valid BaseRequestVo<QueryFmPictureVo> vo) {
        QueryFmPictureVo queryCondition = vo.getEntity(QueryFmPictureVo.class);
        List<SyncPhotoInfo> resultList = iFmPictureService.getPictureInfoList(queryCondition);
        return ResultUtil.success(null, resultList);
    }

}
